package com.sunsheng.modules.juc;

import java.util.concurrent.*;
//异步调用
public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> completableFuture1 = CompletableFuture.runAsync(() -> {
            System.out.println("异步无返回调用");
        });
        completableFuture1.get();

        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("异步有返回调用");
            return 1;
        });
        completableFuture2.whenComplete((t, u) -> {
            System.out.println("方法返回值-" + t);
            System.out.println("方法异常-" + u);
        }).get();
    }
}